$().ready(function() {
	validateRule();
});
$(function(){
    $("#entryTime,#leaveTime").datetimepicker({
        language: 'zh-CN',
        format: 'yyyy-mm-dd',//显示格式
        todayHighlight: 1,//今天高亮
        initialDate: new Date(),//初始化当前日期
        startView:3,
        minView: 2,//设置只显示到分钟
        forceParse: 0,
        showMeridian: 1,
        todayBtn : true,
        autoclose: 1//选择后自动关闭
    });
})
$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function getCheckedRoles() {
    var adIds = "";
    $("input:checkbox[name=role]:checked").each(function(i) {
        if (0 == i) {
            adIds = $(this).val();
        } else {
            adIds += ("," + $(this).val());
        }
    });
    return adIds;
}
function save() {
    $("#roleIds").val(getCheckedRoles());
	$.ajax({
		cache : true,
		type : "POST",
		url : "/sys/staff/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入姓名"
			}
		}
	})
}